<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__ADMIN__/css/login.css">
    <link rel="stylesheet" href="__STATIC__/common/jqueryWeui/weui.min.css">
    <link rel="stylesheet" href="__STATIC__/common/jqueryWeui/jquery-weui.min.css">
    <script>if(window.top !== window.self){ window.top.location = window.location;}</script>
</head>
<body>
    <div class="login-box">
        <div class="content">
            <span class="title">XCMS登录</span>
            <div class="input-box">
                <input type="text" name="admin_name" placeholder="登录名" class="login-input" id="admin_name"/>
            </div>
            <div class="input-box">
                <input type="password" name="admin_password" placeholder="密码" class="login-input" style="margin-top: 30px" id="admin_password"/>
            </div>
            <div class="input-box2">
                <input type="text" name="admin_name" placeholder="验证码" class="verify-input" id="verify_code"/>
                <div style="width: 200px;height: 40px;float: right;cursor: pointer">
                    <img src="{:captcha_src()}" alt="captcha" height="40px" width="130px" onclick="changeCaptcha(this)" id="captcha"/>
                </div>
            </div>
            <div class="login-btn" id="sub">
                登   录
            </div>
        </div>
    </div>
    <script src="__COMMON__/jquery.min.js"></script>
    <script src="__STATIC__/common/jqueryWeui/jquery-weui.min.js"></script>
    <script>
        function changeCaptcha(obj) {
            $(obj).attr('src', $(obj).attr('src') + '?t=' + Math.random());
        }

        $(function () {
            $('#sub').click(function () {
                doLogin();
            });
        });

        document.onkeydown=function(event){
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if(e && e.keyCode==13){ // enter 键
                doLogin();
            }
        };

        function doLogin() {

            var adminName = $("#admin_name").val();
            var adminPassword = $("#admin_password").val();
            var verifyCode = $("#verify_code").val();

            if (adminName == '') {
                $.toast("请输入用户名", "text");
                return false;
            }

            if (adminPassword == '') {
                $.toast("请输入密码", "text");
                return false;
            }

            if (verifyCode == '') {
                $.toast("请输入验证码", "text");
                return false;
            }

            $.showLoading("登录中...");
            $.post('{:url("login/doLogin")}', {
                admin_name: adminName,
                admin_password: adminPassword,
                verifyCode: verifyCode
            }, function (res) {
                $.hideLoading();
                if (0 == res.code) {
                    $.toast(res.msg);
                    setTimeout(function () {
                       window.location.href = '/xcms.php';
                    }, 800);
                } else {
                    $("#captcha").click();
                    $.toast(res.msg, "text");
                }
            }, 'json');
        }
    </script>
</body>
</html>